package com.aplink.generic.xmlparser;

import org.w3c.dom.Node;

import android.text.TextUtils;

import com.aplink.generic.pojo.controlspec.viewpager.ViewPagerSpec;

public class ViewPagerParser {
	public static final String HEADER_STYLE = "headerStyle";
	public static final String OFF_SCREEN_PAGE_LIMIT = "offScreenPageLimit";
	public static final String PAGE_TRANSFORMER = "pageTransformer";

	public static ViewPagerSpec parse(final Node node) {
		final ViewPagerSpec pagerSpec = new ViewPagerSpec();
		if (node.hasAttributes()) {
			final String pageTransform = XmlPaserUtil.getAttrValue(node,
			        PAGE_TRANSFORMER);
			if (!TextUtils.isEmpty(pageTransform)
			        && pageTransform.equalsIgnoreCase("Y")) {
				pagerSpec.setHasPageTransformer(true);
			}

			final String mViewpagerHeaderStyle = XmlPaserUtil.getAttrValue(
			        node, HEADER_STYLE);
			if (!TextUtils.isEmpty(mViewpagerHeaderStyle)) {
				pagerSpec.setHeaderStyle(mViewpagerHeaderStyle);
			}
			final String offScreenLimit = XmlPaserUtil.getAttrValue(node,
			        OFF_SCREEN_PAGE_LIMIT);
			if (!TextUtils.isEmpty(offScreenLimit)) {
				pagerSpec.setOffscreenPageLimit(Integer
				        .parseInt(offScreenLimit));
			}
		}
		pagerSpec.setPageCollection(PageCollectionParser.parse(node));
		return pagerSpec;
	}
}
